using Game.Const;
using Game.Core;
using Game.Main.Model;
using Game.Manager;
using Game.XH;
using UnityEngine;

namespace Game.Component
{
	public class RazorItem : BaseItem
	{
		private GameObject targetObject;

		private BaseItem targetItem;

		private float stayTime;

		private Vector3 originalPos;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
			originalPos = model.localPosition;
		}

		protected override void LateUpdate()
		{
			base.LateUpdate();
			if (targetItem != null)
			{
				stayTime += Time.deltaTime;
				if (stayTime > 0.6f)
				{
					((CharacterItem)targetItem).SetHair(0);
					Singleton<AudioManager>.Instance.PlaySound("sound_blink");
					Singleton<EffectManager>.Instance.ShowEffect(PathConst.EFFECT + "efc_blink_1", targetItem.transform.position + new Vector3(0f, 2.8f, -0.0004f), 3f);
					targetObject = null;
					targetItem = null;
				}
			}
			if (isDrag)
			{
				model.SetLocalXY(originalPos.x + Random.Range(-0.01f, 0.01f), originalPos.y + Random.Range(-0.01f, 0.01f));
			}
		}

		protected override void OnItemCompTriggerEnter(ColliderData collData)
		{
			base.OnItemCompTriggerEnter(collData);
			if (targetObject == null && collData.trigger.type == ItemComponentTrigger.Type.Head)
			{
				targetObject = collData.coll.gameObject;
				targetItem = collData.trigger.owner;
				stayTime = 0f;
			}
		}

		protected override void OnItemCompTriggerExit(ColliderData collData)
		{
			base.OnItemCompTriggerExit(collData);
			if (targetObject != null && collData.coll.gameObject == targetObject)
			{
				targetObject = null;
				targetItem = null;
				stayTime = 0f;
			}
		}

		public override void TouchUp(TouchEventData touchEventData)
		{
			targetObject = null;
			targetItem = null;
			stayTime = 0f;
			model.SetLocalXY(originalPos.x, originalPos.y);
			base.TouchUp(touchEventData);
		}
	}
}
